package com.l.utils;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class BaiDuTime {

	private BaiDuTime() {
		
	}

	public static String getTime() {
		Date date = null;
		DateFormat df=null;
		try {
			URL url = new URL("http://www.baidu.com");	//取得资源对象
			URLConnection uc = url.openConnection();	//生成链接对象
			uc.connect();								//发起链接
			long ld = uc.getDate();						//取得网站日期时间long
			date = new Date(ld);						//转换时间对象
			df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return df.format(date);
	}
	public static void main(String[] args) {
		System.out.println(BaiDuTime.getTime());
	}

}
